import { ApiCall } from "tsrpc";
import { ReqRegHall, ResRegHall } from "../../../tsrpc/shared/protocols/gate/PtlRegHall";
import { gs } from "../../../GateServiceEntra";

export default async function (call: ApiCall<ReqRegHall, ResRegHall>) {
    // TODO
    if (call.req.ip.length == 0 || call.req.port.length == 0 || call.req.name.length == 0) {
        return call.error("注册大厅信息错误", {code:"REG_HALL_INFO_ERR"});
    }

    //删除重复的服务器
    for (let i = 0; i < gs.GateModel.hallList.length; i++) {
        if (gs.GateModel.hallList[i].name == call.req.name) {
            gs.GateModel.hallList.splice(i, 1);
            break;
        }
    }
    //注册大厅服务器
    gs.GateModel.hallList.push({
        name: call.req.name,
        server: `${call.conn.ip}:${call.req.port}`
    })
    call.succ({});
}